package guoanmaker.provider.business.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import guoanmaker.provider.business.model.PersonalFinanceProjectPartner;

/**
 * 金融项目合伙人Dao
 * @author ws
 * 2017-12-22
 */

@Repository
public class PersonalFinanceProjectPartnerDao {

	@PersistenceContext
	EntityManager em;
	
	/**
	 * 根据金融服务项目id和flag查询金融服务合伙人
	 * @param projectId
	 * 			金融服务id
	 * @param flag
	 * 			0:创始人, 1:合伙人
	 * @return
	 */
	public List<PersonalFinanceProjectPartner> findByProjectIdAndFlag(String projectId, Integer flag){
		if(projectId == null || projectId.trim().length() == 0 || flag == null){
			return null;
		}
		
		String sql = "select * "
				+ " from t_personal_finance_project_partner"
				+ " where finance_project_id = :projectId and flag = :flag";
		
		Query query = em.createNativeQuery(sql, PersonalFinanceProjectPartner.class);
		query.setParameter("projectId", projectId);
		query.setParameter("flag", flag);
		
		List<PersonalFinanceProjectPartner> list = query.getResultList();
		
		return list;
		
	}
	
}
